package com.lupan.spring.kafka.controller;


import com.lupan.spring.kafka.service.EcuVersionKafkaService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.listener.MessageListener;
import org.springframework.stereotype.Component;


/**
 * Created by jensen on 10/27/16.
 */
@Component
public class KafkaMsgListener implements MessageListener<String, String> {

    private static final Logger logger = LoggerFactory.getLogger(KafkaMsgListener.class);

    @Autowired
    private EcuVersionKafkaService ecuVersionKafkaService;

    @Override
    public void onMessage(ConsumerRecord<String, String> consumerRecord) {
        try {
            logger.info("消费ecu版本号kafka消息，内容：{}",consumerRecord.value());
            ecuVersionKafkaService.updateEcuVersion(consumerRecord.value());
        } catch (Exception e) {
            logger.error("ecu版本号消息处理失败：",e);
        }
    }
}
